package com.ruoyi.web.controller.system;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.KeyAlertService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.ruoyi.system.domain.KeyAlert;

/**
 * 按键报警表(KeyAlert)表控制层
 * @since 2023-03-27 17:57:22
 */
@RestController
@RequestMapping("keyAlert")
public class KeyAlertController extends BaseController {

    @Resource
    private KeyAlertService keyAlertService;

    /**
     * 分页查询
     * @param keyAlert 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo queryByPage(KeyAlert keyAlert) {
        startPage();
        List<KeyAlert> keyAlerts = this.keyAlertService.queryByPage(keyAlert);
        return getDataTable(keyAlerts);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<KeyAlert> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.keyAlertService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param keyAlert 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<KeyAlert> add(KeyAlert keyAlert) {
        return ResponseEntity.ok(this.keyAlertService.insert(keyAlert));
    }

    /**
     * 编辑数据
     *
     * @param keyAlert 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<KeyAlert> edit(KeyAlert keyAlert) {
        return ResponseEntity.ok(this.keyAlertService.update(keyAlert));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.keyAlertService.deleteById(id));
    }

}

